package com.juc.threadPoolExecutor.threadPoolExecutor17;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 
 * 方法remove(Runnable)
 * 可以删除尚未被执行的Runnable任务
 */
public class Test1 {

	public static void main(String[] args) throws InterruptedException {
		Runnable runnable = new Runnable() {
			
			@Override
			public void run() {
				try {
					System.out.println(Thread.currentThread().getName() + " begin ");
					Thread.sleep(5000);
					System.out.println(Thread.currentThread().getName() + " end ");
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 100, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>());
		executor.execute(runnable);
		Thread.sleep(1000);
		executor.remove(runnable);
		System.out.println("任务正常执行不能删除");
	}
}
